package com.peng.panels;

import com.peng.data.WakCommonData;
import com.peng.event.WakGnTabPanelChangeListener;

import javax.swing.*;
import java.util.Iterator;
import java.util.Set;

/**
 * @author : pengyf
 * @version : 1.0
 * @createTime : 2022/1/22 11:20
 * @Description : TODO
 */
public class WakGnTabsdPanel extends JTabbedPane {
    // 初始化tabs标签
    {
        WakCommonData.WAKTABS.put("参数加解密", new WakParmsEadPanel("参数加解密"));
        WakCommonData.WAKTABS.put("研发中...", new JPanel());
    }

    public WakGnTabsdPanel() {
        super(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT);
        load();
    }

    public void load(){
        setName("功能选项卡");
        // 加载tabs
        Set<String> tabNames = WakCommonData.WAKTABS.keySet();
        Iterator<String> iterator = tabNames.iterator();
        while (iterator.hasNext()){
            String tabName = iterator.next();
            add(tabName, WakCommonData.WAKTABS.get(tabName));
        }
        //设置默认的选项卡页，方式一：通过选项卡的索引
        setSelectedIndex(0);
        //获取当前卡页的选项卡索引
        //int index = getSelectedIndex();
        //获取当前卡页的选项卡面板
        //JPanel jPanel = (JPanel)getSelectedComponent();
        //System.out.println("初始化选择面板为："+jPanel.getName());
        //为选项卡添加监听器
        addChangeListener(new WakGnTabPanelChangeListener());
    }

}
